﻿/*
	Copyright (C) 2019 Zongming Liu <1849059316@qq.com>

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.
	
	You should have received a copy of the GNU General Public License along
	with this program; if not, write to the Free Software Foundation, Inc.,
	51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef Label_h__
#define Label_h__

#include "Widget.h"
#include <string>
#include "../utility/SmartPtrDef.h"
#include "Alignment.h"

namespace SkyEngine2d
{
	class Scale9Image;
	
	/*!
	 \brief 标签控件
	*/
	class SGE_API Label
		: public Widget
	{
		UI_CLASS(Label)
	
	public:
	
		static Label* create(Widget* parent = nullptr);
	
		//!析构
		~Label();
	
		//! 设置文本
		/*!
		\param const std::wstring & text 文本
		\return void  
		*/
		void setText(const std::wstring& text);
	
		//! 获取文本
		/*!
		\return const std::wstring &  
		*/
		const std::wstring & getText()const;
		
		//! 获取图片
		/*!
		\return const std::unique_ptr<Scale9Image>&  
		*/
		const std::unique_ptr<Scale9Image>& getImage()const;
	
		//! 设置图片
		/*!
		\param std::unique_ptr<Scale9Image> image 图片
		\return void  
		*/
		void setImage(std::unique_ptr<Scale9Image> image);
	
		//! 是否开启自动换行
		/*!
		\return bool  
		*/
		bool wordWrap() const;
	
		//! 设置是否自动换行
		/*!
		\param bool word_wrap 
		\return void  
		*/
		void setWordWrap(bool word_wrap);
	
		Alignment getAlignemt()const;
	
		void setAlignment(Alignment alignment);
	protected:
	
		Label(Widget* parent = nullptr);
	
		virtual int getDefultWidth() const override;
	
		virtual int getDefultHeight() const override;
	
		virtual void draw(IRender* render, const Matrix4X4& transform) override;
	
		virtual void onMoveEvent(EventWidgetMove* e) override;
	
		virtual void onResizeEvent(EventResize* e) override;
	
	private:
		TextSharedPtr m_textRender;
		std::wstring  m_text;
		std::unique_ptr<Scale9Image> m_image;
		bool  m_isWordWrap;
		Alignment  m_aligment;
	
		virtual void onWidgetStateChange() override;
		virtual void onWidgetStyleChange() override;
		void updateStyleInfo();
	};
}

#endif // Label_h__
